/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Entry.EntryType;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_64380_63587
/*     */   extends UpgradeOp
/*     */ {
/*     */   private static final String ATTR_NAME = "zimbraGalLdapFilterDef";
/*  41 */   private static List<Pair> VALUES = Lists.newArrayList(new Pair[] { new Pair("zimbraSync:(&(|(displayName=*)(cn=*)(sn=*)(gn=*)(mail=*)(zimbraMailDeliveryAddress=*)(zimbraMailAlias=*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(zimbraHideInGal=TRUE))(!(zimbraIsSystemResource=TRUE)))", "zimbraSync:(&(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(&(objectclass=zimbraCalendarResource)(!(zimbraAccountStatus=active))))(!(zimbraHideInGal=TRUE))(!(zimbraIsSystemResource=TRUE)))"), new Pair("zimbraAccountSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))", "zimbraAccountSync:(&(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))"), new Pair("zimbraResourceSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(objectclass=zimbraCalendarResource))", "zimbraResourceSync:(&(objectclass=zimbraCalendarResource)(zimbraAccountStatus=active))"), new Pair("zimbraGroupSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(objectclass=zimbraDistributionList))", "zimbraGroupSync:(objectclass=zimbraDistributionList)"), new Pair("zimbraResources:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(objectclass=zimbraCalendarResource))", "zimbraResources:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(objectclass=zimbraCalendarResource)(zimbraAccountStatus=active))"), new Pair("zimbraResourceAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(objectclass=zimbraCalendarResource))", "zimbraResourceAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(objectclass=zimbraCalendarResource)(zimbraAccountStatus=active))") });
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  66 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  68 */       doGlobalConfig(zlc);
/*     */     } finally {
/*  70 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   Description getDescription()
/*     */   {
/*  76 */     StringBuilder oldValues = new StringBuilder();
/*  77 */     StringBuilder newValues = new StringBuilder();
/*  78 */     for (Pair valuePair : VALUES) {
/*  79 */       oldValues.append(valuePair.getFirst() + "\n");
/*  80 */       newValues.append(valuePair.getSecond() + "\n");
/*     */     }
/*     */     
/*  83 */     return new Description(this, new String[] { "zimbraGalLdapFilterDef" }, new Entry.EntryType[] { Entry.EntryType.GLOBALCONFIG }, oldValues.toString(), newValues.toString(), String.format("Upgrade zimbraSync, zimbraAccountSync, zimbraResourceSync, and zimbraGroupSync GAL filters on %s on global config from matched old values to the corresponding new value.  This upgrade step covers bug 64380 and 63587.", new Object[] { "zimbraGalLdapFilterDef" }));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doEntry(ZLdapContext zlc, Entry entry)
/*     */     throws ServiceException
/*     */   {
/*  96 */     String entryName = entry.getLabel();
/*     */     
/*  98 */     this.printer.println();
/*  99 */     this.printer.println("------------------------------");
/* 100 */     this.printer.println("Checking zimbraGalLdapFilterDef on " + entryName);
/*     */     
/* 102 */     Set<String> curValues = entry.getMultiAttrSet("zimbraGalLdapFilterDef");
/*     */     
/* 104 */     Map<String, Object> attrs = new HashMap();
/* 105 */     for (Pair<String, String> valuePair : VALUES) {
/* 106 */       String oldValue = (String)valuePair.getFirst();
/* 107 */       String newValue = (String)valuePair.getSecond();
/* 108 */       if (curValues.contains(oldValue)) {
/* 109 */         StringUtil.addToMultiMap(attrs, "-zimbraGalLdapFilterDef", oldValue);
/* 110 */         StringUtil.addToMultiMap(attrs, "+zimbraGalLdapFilterDef", newValue);
/*     */       }
/*     */     }
/* 113 */     modifyAttrs(entry, attrs);
/*     */   }
/*     */   
/*     */   private void doGlobalConfig(ZLdapContext zlc) throws ServiceException {
/* 117 */     doEntry(zlc, this.prov.getConfig());
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_64380_63587.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */